package com.sg.business.model;

import com.mobnut.commons.util.file.FileUtil;
import com.mobnut.db.DBActivator;
import com.mobnut.db.model.ModelService;
import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.sg.business.model.ProjectSetFolder;
import com.sg.business.resource.BusinessResource;
import com.sg.business.resource.nls.Messages;

public class OwnerProjectSetFolder extends ProjectSetFolder {

	@Override
	public Object[] getChildren() {
		DBCollection collection = DBActivator.getCollection(IModelConstants.DB,
				IModelConstants.C_USERPROJECTPERF);
		DBCursor cur = collection.find(new BasicDBObject().append(
				UserProjectPerf.F_USERID, user.getUserid()));
		Object[] result = new Object[cur.size()];
		for (int i = 0; i < result.length; i++) {
			result[i] = ModelService.createModelObject(cur.next(),
					UserProjectPerf.class);
		}
		cur.close();
		return result;
	}

	@Override
	public boolean hasChildren() {
		DBCollection collection = DBActivator.getCollection(IModelConstants.DB,
				IModelConstants.C_USERPROJECTPERF);
		return collection.find(
				new BasicDBObject().append(UserProjectPerf.F_USERID,
						user.getUserid())).count() > 0;
	}

	@Override
	public String getLabel() {
		return Messages.get().OwnerProjectSetFolder_0;
	}

	@Override
	public String getImageURL() {
		return FileUtil.getImageURL(BusinessResource.IMAGE_OWNER_FOLDER_32, BusinessResource.PLUGIN_ID); //$NON-NLS-1$
	}

	@Override
	public String getDescription() {
		return Messages.get().OwnerProjectSetFolder_2;
	}
}
